<template>
	<!-- 右边的发送人 -->
	<div class="goeasy-audio-player" @click="playAudio">
		<div class="audio-facade" :style="{width:Math.ceil(duration)*7 + 50 + 'px'}">
			<div>{{Math.ceil(duration) || 1}}</div>
			<div class="audio-facade-bg" :class="{'play-icon':play}"> </div>
		</div>
	</div>
</template>

<script>
	const innerAudioContext = uni.createInnerAudioContext();
	export default {
		name: "GoEasyAudioPlayerFromDoctor",
		props: ['src', 'duration'],
		data() {
			return {
				play: false
			}
		},
		methods: {
			playAudio() {
				innerAudioContext.src = ''
				if (!this.play) {
					this.play = true;
					innerAudioContext.src = this.src;
					innerAudioContext.play();

				} else {
					this.play = false;
					innerAudioContext.pause();
				}
				// this.play = true;
				// innerAudioContext.src = this.src;
				// innerAudioContext.play();
				setTimeout(() => {
					this.play = false;
				}, this.duration * 1000)
			}
		}
	}
</script>

<style scoped>
	.goeasy-audio-player {
		margin-top: 12rpx;
		-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
	}

	.audio-facade {
		min-width: 20rpx;
		max-width: 420rpx;
		padding: 6rpx 10rpx;
		height: 72rpx;
		line-height: 72rpx;
		background: #50C9BD;
		font-size: 24rpx;
		border-radius: 14rpx;
		color: #ffffff;
		display: flex;
	}

	.audio-facade-bg {
		background: url("./images/voice.png") no-repeat center;
		background-size: 30rpx;
		width: 40rpx;
		-moz-transform: rotate(180deg);
		-webkit-transform: rotate(180deg);
		-o-transform: rotate(180deg);
		transform: rotate(180deg);
	}

	.audio-facade-bg.play-icon {
		background: url("./images/icon_bofang.gif") no-repeat center;
		background-size: 30rpx;
		-moz-transform: rotate(180deg);
		-webkit-transform: rotate(180deg);
		-o-transform: rotate(180deg);
		transform: rotate(180deg);
		/* -moz-transform:rotate(0);
		-webkit-transform:rotate(0);
		-o-transform:rotate(0);
		transform:rotate(0); */
	}
</style>
